/*
 * 一些自定义的jQuery事件统一放在这边
 */

$.dragManager = {

    current: null,

    droppables: [],

    _thresholdDis: 25,

    overed: false,

    prepareOffsets: function() {
        var m       = this.droppables,
            offsets = [];
        for(var i = 0; i < m.length; i++){
            offsets.push(m[i].getTranslate());
        }
    },

    _over: function(droppable){
        var draggable = this.current;
        if($(draggable)[0].compareDocumentPosition($(droppable)[0])){
            return false;
        }
        $(droppable).trigger('dragover');
    },

    _out: function(){

    },

    drag: function(){
        if(!this._current){
            return false;
        }
        var curTrans  = this.current.getTranslate(),
            drops     = this.droppables,
            dropTrans;
        for(var i = 0; i < drops.length; i++){
            dropTrans = $(drops[i]).getTranslate;
            if(Math.abs(dropTrans.x - curTrans.x) < this._thresholdDis && Math.abs(dropTrans.y - curTrans.y) < this._thresholdDis){
                this._over(drops[i], event);
                break;
            }
        }
    }
};

$.fn.droppable = function(){
    $.dragManager.push(this);
};
